package com.jilefojing.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import tk.mybatis.mapper.entity.Example;

import com.jilefojing.beans.pojos.Favorite;
import com.jilefojing.beans.pojos.User;
import com.jilefojing.dao.IFavoriteDao;
import com.jilefojing.dao.base.impl.BaseDao;
import com.jilefojing.dao.mapper.IFavoriteMapper;
import com.jilefojing.util.Detect;

/**
 * 
 * @author 作者 jgshun
 * @date 创建时间 2016年07月23日 02时17分03秒
 */
@Repository
public class FavoriteDao extends BaseDao<Favorite> implements IFavoriteDao {
	@Autowired
	private IFavoriteMapper favoriteMapper;

	@Override
	public Favorite getByNameForUser(String name, User user) {
		Example example = new Example(Favorite.class);
		example.createCriteria().andEqualTo(Favorite.FIELD_NAME, name).andEqualTo(Favorite.FIELD_USERID, user.getId());
		List<Favorite> favorites = super.getListByExample(example);
		if (!Detect.notEmpty(favorites)) {
			return null;
		}
		return favorites.get(0);
	}
}
